Skip to content

(MODULES-11831) Add module_coverage reusable workflow#179

Open
imaqsood wants to merge 1 commit into
mainfrom
MODULES-11831-coverage-gate
Open

(MODULES-11831) Add module_coverage reusable workflow#179
imaqsood wants to merge 1 commit into
mainfrom
MODULES-11831-coverage-gate

Conversation

@imaqsood

Copy link
Copy Markdown
Contributor

What

Adds a reusable Module Coverage workflow that enforces Ruby unit-test coverage on a Puppet module using SimpleCov. Consumed by the new coverage.yml workflow synced from pdk-templates (companion PR).

How it works

  • Runs bundle exec rake spec with COVERAGE=yes (SimpleCov hook lives in the modules spec_helper.rb).
  • Parses coverage/.last_run.json for line coverage and gates the build in one of two modes:
    • absolute - fail if line coverage is below threshold (default 80).
    • baseline_mode - read .coverage_baseline from the repo root; fail on regression, stay green and suggest a new baseline when coverage rises. Missing baseline = 0 = no-op gate (non-breaking rollout).
  • Uploads the LCOV report as a build artifact (actions/upload-artifact).
  • Posts/updates a coverage comment on the PR (actions/github-script).

Inputs: threshold, baseline_mode, ruby_version, runs_on. Caller must grant pull-requests: write.

Ticket

MODULES-11831 (S2 maturity coverage gate, epic MODULES-11828).

Merge order

Merge this before the pdk-templates PR, which references module_coverage.yml@main.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new reusable GitHub Actions workflow intended to enforce Ruby unit-test line coverage (via SimpleCov) for Puppet modules, including optional baseline gating and automated PR commenting.

Changes:

  • Introduces .github/workflows/module_coverage.yml reusable workflow with workflow_call inputs for threshold/baseline mode, Ruby version, and runner OS.
  • Adds a coverage gate step that reads coverage/.last_run.json, supports absolute and baseline gating, and fails the workflow when coverage is below the configured target.
  • Uploads LCOV artifacts and posts/updates a PR coverage summary comment via actions/github-script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/module_coverage.yml Outdated
Comment thread .github/workflows/module_coverage.yml Outdated
Comment thread .github/workflows/module_coverage.yml Outdated
if-no-files-found: "warn"

- name: "Post coverage comment"
if: ${{ always() && github.event_name == 'pull_request' }}
Comment thread .github/workflows/module_coverage.yml Outdated
@imaqsood imaqsood force-pushed the MODULES-11831-coverage-gate branch from 80cc227 to 4b07e86 Compare June 24, 2026 14:21
imaqsood added a commit that referenced this pull request Jun 24, 2026
Address Copilot review feedback on PR #179:

- Pin actions/checkout and ruby/setup-ruby to commit SHAs and set
  persist-credentials: false on checkout, matching the hardened pattern
  in module_ci.yml. Also pin upload-artifact and github-script.
- Run the coverage comment step on pull_request_target as well as
  pull_request, so fork PRs that need pull-requests: write still get
  the summary.
- Paginate issues.listComments so the marker comment is found even when
  it drifts past the first page, preventing duplicate coverage comments.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@imaqsood imaqsood force-pushed the MODULES-11831-coverage-gate branch from 01be623 to 952e16c Compare June 28, 2026 16:24
Reusable workflow enforcing Ruby unit-test line coverage (SimpleCov) on a
Puppet module. Runs `bundle exec rake spec` with COVERAGE=yes, parses
coverage/.last_run.json, and gates in absolute mode (fail below threshold,
default 80) or baseline mode (fail on regression vs .coverage_baseline,
suggest a new floor when coverage rises). Uploads the LCOV report and
posts/updates a coverage comment on the PR.

Inputs: threshold, baseline_mode, ruby_version, runs_on. Caller must grant
pull-requests: write.

Actions are pinned to commit SHAs with persist-credentials: false on
checkout (matching module_ci.yml); the comment step runs on both
pull_request and pull_request_target, and listComments is paginated so the
marker comment is found on long PRs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@imaqsood imaqsood force-pushed the MODULES-11831-coverage-gate branch from 952e16c to 455f49f Compare June 28, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants